package org.cytoscape.myapp.cytoscape_app_v1.internal;

import javax.swing.JPanel;
import java.awt.TextArea;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.TextField;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
import javax.swing.Action;


import org.cytoscape.myapp.cytoscape_app_v1.internal.Constants.Selection;

import java.awt.Color;

public class SubComponent extends JPanel {
	
	protected JTextField textFieldWords;
	protected JTextField textFieldNameGroup;
	protected JComboBox<Selection> comboBoxComparator;
	protected JCheckBox chckbxCaseSensitiveCheckBox;
	private JButton btnBorrar;
	private final Action action = new SwingAction();
	private SubComponent Panel = this;
	private JPanel panelPadre;
	
	public JTextField getTextFieldWords() {
		return textFieldWords;
	}



	public void setTextFieldWords(JTextField textFieldWords) {
		this.textFieldWords = textFieldWords;
	}



	public JTextField getTextFieldNameGroup() {
		return textFieldNameGroup;
	}



	public void setTextFieldNameGroup(JTextField textFieldNameGroup) {
		this.textFieldNameGroup = textFieldNameGroup;
	}



	public JComboBox getComboBoxComparator() {
		return comboBoxComparator;
	}



	public void setComboBoxComparator(JComboBox comboBoxComparator) {
		this.comboBoxComparator = comboBoxComparator;
	}



	public JCheckBox getChckbxCaseSensitiveCheckBox() {
		return chckbxCaseSensitiveCheckBox;
	}



	public void setChckbxCaseSensitiveCheckBox(JCheckBox chckbxCaseSensitiveCheckBox) {
		this.chckbxCaseSensitiveCheckBox = chckbxCaseSensitiveCheckBox;
	}


	/**
	 * Create the panel.
	 */
	public SubComponent(JPanel panelPadre) {
		setBorder(new LineBorder(Color.GRAY));
		this.panelPadre = panelPadre;

		textFieldWords = new JTextField();
		textFieldWords.setColumns(10);
		
		comboBoxComparator = new JComboBox();
	
		comboBoxComparator.addItem(Selection.EQUALS);
		comboBoxComparator.addItem(Selection.CONTAINS);
		
		chckbxCaseSensitiveCheckBox = new JCheckBox("Case Sense");
		
		JLabel lblNombreGrupo = new JLabel("Nombre Grupo:");
		
		textFieldNameGroup = new JTextField();
		textFieldNameGroup.setColumns(10);
		btnBorrar = new JButton("Borrar");
		btnBorrar.setAction(action);
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(12)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblNombreGrupo)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textFieldNameGroup, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addComponent(chckbxCaseSensitiveCheckBox)
							.addPreferredGap(ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
							.addComponent(btnBorrar)
							.addGap(21))
						.addGroup(groupLayout.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textFieldWords, GroupLayout.PREFERRED_SIZE, 166, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addComponent(comboBoxComparator, GroupLayout.PREFERRED_SIZE, 92, GroupLayout.PREFERRED_SIZE)
							.addContainerGap())))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(17)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNombreGrupo)
						.addComponent(textFieldNameGroup, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(chckbxCaseSensitiveCheckBox)
						.addComponent(btnBorrar))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(textFieldWords, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(comboBoxComparator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(22, Short.MAX_VALUE))
		);
		setLayout(groupLayout);

		this.setVisible(true);
	}
	
		private class SwingAction extends AbstractAction {
		public SwingAction() {
			putValue(NAME, "Borrar");
			putValue(SHORT_DESCRIPTION, "Borrar Criterio");
		}
		public void actionPerformed(ActionEvent e) {
			panelPadre.remove(Panel);			
			panelPadre.validate();
			panelPadre.repaint();
		
		}
	}
}
